#include "debug.h"
#include "../DDIC/AllDDIC.h"
#include "../DEMURA/Demura.h"
#include "usbd_cdc.h"

/********************************************************************************************
    Demura  Flashê1?ü
		Demura	Flash2á3y
		Demura	FlashD′è?
		Demura	FlashD￡?é
		Demura	Flash OTP
		Demura	1|?ü?a??&1?±?
********************************************************************************************/
//{0xfe,0x26,0xf3,0x02,0x18,(USB_Rx_Demura_Total_Num>>16),0x19,(USB_Rx_Demura_Total_Num>>8),0x1A,USB_Rx_Demura_Total_Num};
extern u32 USB_Demura_Transmode_start;

void GM862_Enable_Flash_Control_and_SPI_Flash_En(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	u16 tmp=0;
	u8 buffer1[3];	
	
	u8 R66455_Enable_Flash_Control[52]={0x34,0xDF,0x00,0x40,0x58,0x83,0x2D,0x05,0x35,0x15,0x01,0x31,0x11,0x6B,0x50,0x00,0x02,0x00,0x00,0x43,0x84,0x00,0x10,0x00,0xDF,0xD4,0x0E,0x00,0x00,0x13,0xFF,0x8C,0x27,0x17,0x0F,0x00,0x55,0x18,0x0F,0x00,0x1A,0x0F,0x00,0x1C,0x0F,0x00,0x1E,0x0F,0x00,0x00,0x00,0x00}; 
	u8 R66455_RDID[7]={0x06,0xf3,0x9f,0x00,0x00,0x00,0x02};
	
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);		
	delay_ms(5);
	buffer1[0] = 0x02;
	buffer1[1] = 0xB0;
	buffer1[2] = 0x00;
	SSD2828_W_Array(SigMode,channel,buffer1,0);
	delay_ms(2);
	SSD2828_W_Array(SigMode,channel,R66455_Enable_Flash_Control,0);
	delay_ms(2);
	SSD2828_W_Array(SigMode,channel,R66455_RDID,0);
	delay_ms(2);
	buffer1[1] = 0xf2;
	buffer1[2] = 0x09;
	SSD2828_W_Array(SigMode,channel,buffer1,0);
	delay_ms(15);
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);                               
	SSD2828_W_Reg(SigMode,channel,0xC1,0x0003); //return package size                                
	SSD2828_W_Reg(SigMode,channel,0xC0,0x0001); //reset

	buffer1[0] = 0x01;
	buffer1[1] = 0xf4; 	//download register 
	SSD2828_W_Array(SigMode,channel,buffer1,0);
	delay_ms(5);  
	SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
	SSD2828_W_Cmd(SigMode,channel,0xFF);


	for(i=0;i<3;i++)  //data read out length
	{
		SSD2828_W_Cmd(SigMode,channel,0xFA);		
		tmp=SPI3_Read_u16_Data(channel);
		buffer[4+i]=tmp>>8;
		buffer[5+i]=tmp;
		delay_ms(5);
		i++;
	}
	

	//buffer[7]=0x30;
	buffer[0] = 0x2F;
	buffer[1] = 0x06;	
	
	delay_ms(5);
	SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
	STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //·μ?? ?áè?μ? Gammaêy?Y  ￡ook  
}
void GM862_Inter_Demura_Ram(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
//	u8 buffer1[3];
	u8 buffer1[5];
			u8 R66456_Flash_Operate_Function_Table[10]={0x09,0xf3,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
			u8 R66456_Flash_Operate_Function_Table2[10]={0x09,0xf3,0x05,0x00,0x00,0x00,0x00,0x00,0xF4,0x00};
			u8 R66455_Read_REG=0xF4;
			
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	delay_ms(15);
		
			
			USB_Demura_Transmode_start = (buffer[4]<<16) + (buffer[5]<<8) + (buffer[6]<<0);
			
//	R66456_Flash_Write_En_Demura(pdev,SigMode,channel);
	buffer1[0] = 0x02;
			buffer1[1] = 0xB0;
			buffer1[2] = 0x04;
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			buffer1[0] = 0x04;
			buffer1[1] = 0xDF;
			buffer1[2] = 0x5F;
			buffer1[3] = 0x00;
			buffer1[4] = 0x5A;
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			delay_ms(5);					
			SSD2828_W_Array(SigMode,channel,R66456_Flash_Operate_Function_Table,0);
			delay_ms(5);
			buffer1[0] = 0x02;
			buffer1[1] = 0xf2;
			buffer1[2] = 0x11;
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			delay_ms(5);	
//#(2) Read Status Register 1	
			SSD2828_W_Array(SigMode,channel,R66456_Flash_Operate_Function_Table2,0);
			delay_ms(5);	
			buffer1[0] = 0x02;
			buffer1[1] = 0xf2;
			buffer1[2] = 0x09;
			SSD2828_W_Array(SigMode,channel,buffer1,0);	

//			SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
//			delay_ms(5);	
			
	buffer[0] = 0x2F;
	buffer[1] = 0x01;		

	SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
	STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);        																					
}
                                    
void GM862_Exit_Demura_Ram(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
;
}
                               
void GM862_Flash_Write_Demura(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
;	
}                       

void GM862_Flash_Write_Demura2(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
;
}


void GM862_Flash_Check_Demura(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	u16 tmp=0;
	u8 buffer1[3];

	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	delay_ms(15);

	SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0410)&0XFFFD);		
	delay_ms(5);
	buffer1[0] = 0x02;
	buffer1[1] = 0xB0;
	buffer1[2] = 0x00;
	SSD2828_W_Array(SigMode,channel,buffer1,0);
	delay_ms(2);
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);                               
	SSD2828_W_Reg(SigMode,channel,0xC1,0x0008); //return package size                                
	SSD2828_W_Reg(SigMode,channel,0xC0,0x0001); //reset

	buffer1[0] = 0x01;
	buffer1[1] = 0xE7; 	//download register 
	SSD2828_W_Array(SigMode,channel,buffer1,0);
	delay_ms(5);  
	SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
	SSD2828_W_Cmd(SigMode,channel,0xFF);
	for(i=0;i<8;i++)  //data read out length     R66456 6&7   R66456 2&3
	{
	SSD2828_W_Cmd(SigMode,channel,0xFA);		
	tmp=SPI3_Read_u16_Data(channel);
	buffer[4+i]=tmp>>8;
	buffer[5+i]=tmp;
	delay_ms(5);
	i++;
	}
	buffer[4]=buffer[5];   //5
	buffer[5]=buffer[6];  //6
//	buffer[7]=0x30;

	
	delay_ms(5);
	buffer[0] = 0x2F;
	buffer[1] = 0x04;					
    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //·μ?? ?áè?μ? Gammaêy?Y  ￡ook  	
}
                                  
void GM862_Flash_Erase_Demura(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	u32 i=0;
	u8 buffer1[5];
	u8 R66455_Flash_Operate_Function_Table[7]={0x06,0xf3,0x50,0x00,0x00,0x00,0x00};
	u8 R66455_Read_REG=0xF4;	
	u8 Low_address_temp = 0;	
	u8 Middle_address_temp = 0;
	u8 High_address_temp = 0;
	u32 Start_address = 0;
	u32 Start_address_temp = 0;
	
	LP_B7_Data = LP_DCS_Short_Write;
	
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	delay_ms(15);
	
		Start_address =		buffer[4];
		Start_address =	(Start_address<<8) + buffer[5];
		Start_address =	(Start_address<<8) + buffer[6];
	for(i = 0;i<=0xEE000;i+=0x100)
	{////sector  erase  use
			Start_address_temp = Start_address +i;
//			Low_address_temp = Start_address_temp&0xFF;
//			Middle_address_temp = (Start_address_temp>>8)&0xFF;
//			High_address_temp = (Start_address_temp>>16)&0xFF;
		
//		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
//		delay_ms(15);
		
			buffer1[0] = 0x02;
			buffer1[1] = 0xB0;
			buffer1[2] = 0x04;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x02;
			buffer1[1] = 0xF1;
			buffer1[2] = 0x01;
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			buffer1[0] = 0x03;
			buffer1[1] = 0xDF;
			buffer1[2] = 0x40;
			buffer1[3] = 0x58;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			SSD2828_W_Array(SigMode,channel,R66455_Flash_Operate_Function_Table,0);
			buffer1[0] = 0x02;
			buffer1[1] = 0xf2;
			buffer1[2] = 0x11;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(1);
			R66455_Flash_Operate_Function_Table[2]=0x31;
			R66455_Flash_Operate_Function_Table[6]=0x00;
			SSD2828_W_Array(SigMode,channel,R66455_Flash_Operate_Function_Table,0);	
			buffer1[0] = 0x02;
			buffer1[1] = 0xf4;
			buffer1[2] = 0x00;
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			buffer1[0] = 0x02;
			buffer1[1] = 0xf2;
			buffer1[2] = 0x19;
			SSD2828_W_Array(SigMode,channel,buffer1,0);		
			delay_ms(1);
			R66455_Flash_Operate_Function_Table[2]=0x05;
			R66455_Flash_Operate_Function_Table[6]=0x00;
			SSD2828_W_Array(SigMode,channel,R66455_Flash_Operate_Function_Table,0);	
			buffer1[0] = 0x02;
			buffer1[1] = 0xf2;
			buffer1[2] = 0x09;
			SSD2828_W_Array(SigMode,channel,buffer1,0);		
			delay_ms(2);		
			
			SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);
			//delay_ms(5);	
			SSD2828_W_Reg(SigMode,channel,0xBC,0x0001); 
			//SSD2828_W_Reg(SigMode,channel,0xC1,0x0002); //return package  
			do
			{					
				SSD2828_W_Reg(SigMode,channel,0xC1,0x0002); //return package  				
				buffer1[0] = 0x01;
				buffer1[1] = R66455_Read_REG;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 
				delay_ms(6);
				buffer[4] = 0xFF;
				buffer[4]=SSD2828_R_Reg(SigMode,channel,0xFF);
				buffer[4]=SSD2828_R_Reg(SigMode,channel,0xFF);				
			}while((buffer[4]&0x00)!=0x00);		
			SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data); 
			delay_ms(1);	
			R66455_Flash_Operate_Function_Table[2]=0x06;
			SSD2828_W_Array(SigMode,channel,R66455_Flash_Operate_Function_Table,0);	
			buffer1[0] = 0x02;
			buffer1[1] = 0xf2;
			buffer1[2] = 0x11;
			SSD2828_W_Array(SigMode,channel,buffer1,0);		
			delay_ms(1);	
			R66455_Flash_Operate_Function_Table[2]=0x20;
			R66455_Flash_Operate_Function_Table[3]=Start_address_temp&0xFF;////adress low 8bit
			R66455_Flash_Operate_Function_Table[4]=(Start_address_temp>>8)&0xFF;////adress middle 8bit
			R66455_Flash_Operate_Function_Table[5]=(Start_address_temp>>16)&0xFF;////adress high 8bit
			SSD2828_W_Array(SigMode,channel,R66455_Flash_Operate_Function_Table,0);	
			buffer1[0] = 0x02;
			buffer1[1] = 0xf2;
			buffer1[2] = 0x13;
			SSD2828_W_Array(SigMode,channel,buffer1,0);		
			delay_ms(1);	
			R66455_Flash_Operate_Function_Table[2]=0x05;
			R66455_Flash_Operate_Function_Table[3]=0x00;
			R66455_Flash_Operate_Function_Table[4]=0x00;
			R66455_Flash_Operate_Function_Table[5]=0x00;
			SSD2828_W_Array(SigMode,channel,R66455_Flash_Operate_Function_Table,0);	
			buffer1[0] = 0x02;
			buffer1[1] = 0xf2;
			buffer1[2] = 0x09;
			SSD2828_W_Array(SigMode,channel,buffer1,0);		
			delay_ms(2);					
	//----------------------------------------------------------		
			SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);
			//delay_ms(5);	
			SSD2828_W_Reg(SigMode,channel,0xBC,0x0001); 
			//SSD2828_W_Reg(SigMode,channel,0xC1,0x0002); //return package  
			do
			{						 
				SSD2828_W_Reg(SigMode,channel,0xC1,0x0002); //return package  
				buffer1[0] = 0x01;
				buffer1[1] = R66455_Read_REG;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 
				buffer[4] = 0xFF;
				delay_ms(6);
				buffer[4]=SSD2828_R_Reg(SigMode,channel,0xFF);
				buffer[4]=SSD2828_R_Reg(SigMode,channel,0xFF);				
			}while((buffer[4]&0x00)!=0x00);		//busy
		//--------------------------------------------------------
			SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data); 
		}

		{////erase  all code
//			R66455_Flash_Erase_Demura(pdev,SigMode,channel);
//			buffer1[0] = 0x02;
//			buffer1[1] = 0xB0;
//			buffer1[2] = 0x00;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);
//			buffer1[0] = 0x03;
//			buffer1[1] = 0xdf;
//			buffer1[2] = 0x11;
//			buffer1[3] = 0x40;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);	
//			SSD2828_W_Array(SigMode,channel,R66455_Flash_Operate_Function_Table,0);
//			buffer1[0] = 0x02;
//			buffer1[1] = 0xf2;
//			buffer1[2] = 0x11;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);
//			delay_ms(2);
//			R66455_Flash_Operate_Function_Table[2]=0x01;
//			R66455_Flash_Operate_Function_Table[6]=0x01;
//			SSD2828_W_Array(SigMode,channel,R66455_Flash_Operate_Function_Table,0);	
//			buffer1[0] = 0x03;
//			buffer1[1] = 0xf4;
//			buffer1[2] = 0x00;
//			buffer1[3] = 0x00;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);	
//			buffer1[0] = 0x02;
//			buffer1[1] = 0xf2;
//			buffer1[2] = 0x19;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);		
//			delay_ms(2);
//			R66455_Flash_Operate_Function_Table[2]=0x05;
//			R66455_Flash_Operate_Function_Table[6]=0x00;
//			SSD2828_W_Array(SigMode,channel,R66455_Flash_Operate_Function_Table,0);	
//			buffer1[0] = 0x02;
//			buffer1[1] = 0xf2;
//			buffer1[2] = 0x09;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);		
//			delay_ms(2);		
//			R66455_Flash_Operate_Function_Table[2]=0x06;
//			SSD2828_W_Array(SigMode,channel,R66455_Flash_Operate_Function_Table,0);	
//			buffer1[0] = 0x02;
//			buffer1[1] = 0xf2;
//			buffer1[2] = 0x11;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);		
//			delay_ms(2);	
//			R66455_Flash_Operate_Function_Table[2]=0x05;
//			SSD2828_W_Array(SigMode,channel,R66455_Flash_Operate_Function_Table,0);	
//			buffer1[0] = 0x02;
//			buffer1[1] = 0xf2;
//			buffer1[2] = 0x09;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);		
//			delay_ms(2);	
//	//----------------------------------------------------------		
//			SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);
//			delay_ms(5);	
//			SSD2828_W_Reg(SigMode,channel,0xBC,0x0001); 
//			
//			do
//			{						 
//				SSD2828_W_Reg(SigMode,channel,0xC1,0x0001); //return package  
//				buffer1[0] = 0x01;
//				buffer1[1] = R66455_Read_REG;
//				SSD2828_W_Array(SigMode,channel,buffer1,0); 
//				delay_ms(6);
//				buffer[4]=SSD2828_R_Reg(SigMode,channel,0xFF);		
//			}while((buffer[4]&0x02)!=0x02);		
//		//--------------------------------------------------------	
//			SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data); 
//			delay_ms(5);
//			R66455_Flash_Operate_Function_Table[2]=0x60;
//			SSD2828_W_Array(SigMode,channel,R66455_Flash_Operate_Function_Table,0);	
//			buffer1[0] = 0x02;
//			buffer1[1] = 0xf2;
//			buffer1[2] = 0x11;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);		
//			delay_ms(5500);	
//			delay_ms(4000);	
//			R66455_Flash_Operate_Function_Table[2]=0x05;
//			SSD2828_W_Array(SigMode,channel,R66455_Flash_Operate_Function_Table,0);	
//			buffer1[0] = 0x02;
//			buffer1[1] = 0xf2;
//			buffer1[2] = 0x09;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);		
//			delay_ms(2);					
//	//----------------------------------------------------------		
//			SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);
//			delay_ms(15);	
//			SSD2828_W_Reg(SigMode,channel,0xBC,0x0001); 
//			
//			do
//			{						 
//				SSD2828_W_Reg(SigMode,channel,0xC1,0x0001); //return package  
//				buffer1[0] = 0x01;
//				buffer1[1] = R66455_Read_REG;
//				SSD2828_W_Array(SigMode,channel,buffer1,0); 
//				delay_ms(6);
//				buffer[4]=SSD2828_R_Reg(SigMode,channel,0xFF);		
//			}while((buffer[4]&0x00)!=0x00);		//busy
//		//--------------------------------------------------------
//			buffer1[0] = 0x03;
//			buffer1[1] = 0xDF;
//			buffer1[2] = 0x11;
//			buffer1[3] = 0x42;
//			SSD2828_W_Array(SigMode,channel,buffer1,0);
//			delay_ms(5);
			
		}	
	buffer[0] = 0x2F;
	buffer[1] = 0x05;	
	
	//buffer[4] = 0x80;		
	SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
	STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);         
}

void GM862_Flash_Demura_OTP(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
;
}

void GM862_Demura_Function_ON(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	u8 buffer1[7];
//	u8 RM67298_Demura_Function_ON_Table[10]={0xfe,0x20,0x09,0x10,0xA6,0xC0,0xA7,0xFF,0xBC,0x01};

	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	delay_ms(15);	
	
	buffer1[0] = 0x02;
	buffer1[1] = 0xB0;
	buffer1[2] = 0x80;
	SSD2828_W_Array(SigMode,channel,buffer1,0);
	buffer1[1] = 0xD4;
	buffer1[2] = 0x93;
	SSD2828_W_Array(SigMode,channel,buffer1,0);		

	delay_ms(5);
	buffer[0] = 0x2F;
	buffer[1] = 0x07;		
	SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
	STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //êy?Y3¤?è-crcá?×??ú
}

void GM862_Demura_Function_OFF(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	u8 buffer1[7];	
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	delay_ms(15);

	buffer1[0] = 0x02;
	buffer1[1] = 0xB0;
	buffer1[2] = 0x80;
	SSD2828_W_Array(SigMode,channel,buffer1,0);
	buffer1[1] = 0xD4;
	buffer1[2] = 0x90;
	SSD2828_W_Array(SigMode,channel,buffer1,0);		
	
	delay_ms(5);
	buffer[0] = 0x2F;  //Demura_type
	buffer[1] = 0x08;				
	SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
	STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //·μ?? ?áè?μ? Gammaêy?Y  ￡ook  
}

void R66451_GM862_Write_Demura_Ram(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8 buffer[],u16 LP_B7_Data,u16 HS_B7_Data)
{
	//u8 buf2PC[10];
	/*DemuraIctype->IC型号; Demura_OLEDModule_flag->项目号*/
	USB_Rx_Demura_End_Flag=0;	
	if(USB_Rx_Demura==0)//第一笔数据
	{												
		DemuraTransOnce=256*3;
		USB_Rx_Demura=1; //进入Demura数据写入状态														
	}
	for(i=0;i<USB_ReceivedCount;i++)
	{
		buffer[i+VCP_Receive_True_num] = USB_Rx_Buffer[i];  //
	}
	VCP_Receive_True_num+=USB_ReceivedCount;
	DemuraRecivedNum    +=USB_ReceivedCount;				
	//-----------------------------------------------------------------				
	if((VCP_Receive_True_num==DemuraTransOnce)||((DemuraRecivedNum==USB_Rx_Demura_Total_Num))) //写入单笔数据,单次写入DemuraTransOnce个字节
	{												
		R66451_Flash_Write_Demura(pdev,OLED.SigMode,channel,DemuraRecivedNum,buffer,DemuraTransOnce);						
		VCP_Receive_True_num=0;
		
		if(DemuraRecivedNum==USB_Rx_Demura_Total_Num)//最后一笔，状态重置
		{
			Demura_START_FLAG=0;  //清除Demura状态
			DemuraRecivedNum=0; //累计接收统计归零
			USB_Rx_Demura=0;//进入Demura downloading标志
			Demura_first_package_flag=0; //Novatek_NT37700C 4c/5c
		}
	}
}


void ProcessForDmuR0F( USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8 buffer[],u16 LP_B7_Data,u16 HS_B7_Data)
{	
	switch(USB_Rx_Buffer[1])
	{
			case 0x01:                                      //写寄存器
					GM862_Inter_Demura_Ram(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;	
			case 0x02:                                      //读寄存器
					GM862_Exit_Demura_Ram(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;						 
			case 0x03:                                      //读寄存器
					GM862_Flash_Write_Demura(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;	
			case 0x04:                                      //读寄存器
					GM862_Flash_Check_Demura(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;												
			case 0x05:                                      //读寄存器
					GM862_Flash_Erase_Demura(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;
			case 0x06:                                      //check flash ID
					GM862_Enable_Flash_Control_and_SPI_Flash_En(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;	
			case 0x07:                                      //check flash ID
					GM862_Demura_Function_ON(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;	
			case 0x08:                                      //check flash ID
					GM862_Demura_Function_OFF(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;													
			case 0x0A:
					GM862_Flash_Write_Demura2(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;
			default:
				break;												
	}
}
//********************************************************************************************